﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Pacjent.referencja1;
using System.Windows.Navigation;


namespace Pacjent
{
    public partial class pdodajchor : PhoneApplicationPage 
    {
        string pesel = "";
        static referencja1.Service1SoapClient c;
        protected override void OnNavigatedTo(NavigationEventArgs e)

    {
    
    if (NavigationContext.QueryString.TryGetValue("pesel", out pesel))
        pivotdch.Title = "Pacjent: " + pesel;

    }

        public pdodajchor()
        {
            
            InitializeComponent();
            c = new referencja1.Service1SoapClient();
            c.dodajchorobeCompleted += new EventHandler<dodajchorobeCompletedEventArgs>(c_dodajchorobeCompleted);
            c.pobierzidchorobyCompleted += new EventHandler<pobierzidchorobyCompletedEventArgs>(c_pobierzidchorobyCompleted);
            c.pobierzidchorobyAsync();
        }

       
        void c_pobierzidchorobyCompleted(object sender, pobierzidchorobyCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                textBlock6.Text = e.Result;
            }
            else
            {
                MessageBox.Show("blad");
                
            }
        }

        void c_dodajchorobeCompleted(object sender, dodajchorobeCompletedEventArgs e)
        {
            MessageBox.Show("poprawnie dodano chorobe");
        }


         private void PowrotDoMenu()
        {

            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }


        private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
        {
            PowrotDoMenu();
        }

        private void hyperlinkButton2_Click(object sender, RoutedEventArgs e)
        {
            PowrotDoMenu();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            pivotdch.SelectedIndex = 0;
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            
            int idchor = Int32.Parse(textBlock6.Text) + 1;
            string praid = idchor.ToString();
            if (textBox1.Text == "")
            { MessageBox.Show("Sprawdz nazwe choroby"); }
            else if (textBox2.Text == "")
            { MessageBox.Show("Sprawdz date poczatku choroby"); }
            else if (textBox3.Text == "")
            { MessageBox.Show("Sprawdz opis leczenia"); }
            else if (textBox4.Text == "")
            { MessageBox.Show("Sprawdz date zakonczenia choroby"); }
            else if (textBox5.Text == "")
            { MessageBox.Show("Sprawdz sprawdz dane poradni"); }
            else
            c.dodajchorobeAsync(pesel, praid, textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text);

        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
           string dane = pesel+"^^"+textBox1.Text;
           NavigationService.Navigate(new Uri("/pznajdz.xaml?data="+dane, UriKind.Relative));
        }
    }
}